﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hjp.FrameWork.Common;
using Wjtour.Domain;
using Wjtour.BLL;

namespace Wjtour.Web.Admin.ad
{
    public partial class addedi : BasePage
    {
        protected TextBox title;
        protected TextBox img;
        protected TextBox height;
        protected TextBox width;
        protected TextBox link;
        protected RadioButtonList type;
        protected TextBox content;
        protected TextBox adtype;
        protected TextBox edate;
        protected Button submit;
        protected int id = 0;
        Wjtour.Domain.ad entity = new Domain.ad();
        ad_bll _bll = new ad_bll();

        protected void Page_Load(object sender, EventArgs e)
        {
            id = Utils.StrToInt(Request["id"], 0);
            submit.Click += new EventHandler(submit_Click);
            if (id > 0)
            {
                entity = _bll.Load(id);
                if (!IsPostBack)
                {
                    if (entity != null)
                    {
                        title.Text = entity.title;
                        img.Text = entity.img;
                        type.SelectedValue = entity.type.ToString();
                        height.Text = entity.height;
                        width.Text = entity.width;
                        content.Text = entity.content;
                        adtype.Text = entity.adtype;
                        edate.Text = entity.edate == null ? "" : entity.edate.Value.ToString("yyyy-MM-dd");
                    }
                }
            }
        }

        void submit_Click(object sender, EventArgs e)
        {
            entity.id = id;
            entity.title = title.Text;
            entity.img = img.Text;
            entity.type = Utils.StrToInt(type.SelectedValue, 0);
            entity.height = height.Text;
            entity.width = width.Text;
            entity.content = content.Text;
            entity.adtype = adtype.Text;
            entity.addtime = DateTime.Now;
            entity.edate = DateTime.Now;

            bool b = _bll.Save(entity);
            if (b)
            {
                SaveLog(id == 0 ? "Add" : "edit");
                Utils.Alert(this.Page, "保存成功！");
                Utils.Redirect(this.Page, "list.aspx", false);
            }
        }
    }
}